#!/usr/bin/env python3
"""
检查数据库内容的脚本
"""

from app import app, db, Prompt
from datetime import datetime

def check_database():
    """检查数据库内容"""
    with app.app_context():
        print("=" * 50)
        print("数据库检查")
        print("=" * 50)
        
        # 检查总记录数
        total_count = Prompt.query.count()
        print(f"总记录数: {total_count}")
        
        if total_count > 0:
            # 获取所有记录
            all_prompts = Prompt.query.all()
            print(f"\n所有记录:")
            for i, prompt in enumerate(all_prompts, 1):
                print(f"  {i}. ID: {prompt.id}, Chrome ID: {prompt.chrome_id}")
                print(f"     文本: {prompt.text[:50]}...")
                print(f"     收藏: {prompt.is_favorite}")
                print(f"     来源: {prompt.source}")
                print(f"     创建时间: {prompt.created_at}")
                print(f"     更新时间: {prompt.updated_at}")
                print(f"     最后同步: {prompt.last_synced}")
                print()
        
        # 检查按更新时间排序的记录
        print("按更新时间排序的记录:")
        sorted_prompts = Prompt.query.order_by(Prompt.updated_at.desc()).all()
        for i, prompt in enumerate(sorted_prompts, 1):
            print(f"  {i}. {prompt.chrome_id} - {prompt.updated_at}")
        
        # 检查收藏记录
        favorite_count = Prompt.query.filter_by(is_favorite=True).count()
        print(f"\n收藏记录数: {favorite_count}")
        
        if favorite_count > 0:
            favorite_prompts = Prompt.query.filter_by(is_favorite=True).all()
            for prompt in favorite_prompts:
                print(f"  收藏: {prompt.chrome_id} - {prompt.text[:30]}...")

if __name__ == '__main__':
    check_database()
